<!DOCTYPE html>
<html lang="en" style="font-size: 20px;">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            font-size: 2rem;
        }
    </style>
</head>
<body>
    <div>hello world!</div>

    <script>

        // 20 >>> window.innerWidth
        const k = window.innerWidth / 20;

        window.addEventListener('resize', function () {
            const newFontSize = window.innerWidth / k;
            // documentElement >>> html
            document.documentElement.setAttribute('style', `font-size: ${ newFontSize }px;`);
        });

    </script>
</body>
</html>